package com.study.example.gameserver.module.attr.calculator.impl;

import com.sparrow.common.attr.domain.Attr;
import com.sparrow.resource.cache.ResourceCache;
import com.study.example.gameserver.module.attr.domain.AttrConst;
import com.study.example.gameserver.module.attr.domain.AttrType;
import com.study.example.gameserver.module.attr.calculator.AttrCalculator;
import com.study.example.gameserver.module.player.entity.Player;
import com.study.example.gameserver.module.player.resource.LevelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;

@Component
public class LevelAttrCalculator implements AttrCalculator {

    @Autowired
    ResourceCache<Integer, LevelResource> levelResourceCache;

    @Override
    public void calcAttr(Player player) {
        LevelResource levelResource = levelResourceCache.getResource(player.getLevel());
        Map<AttrType, Integer> attr = levelResource.getAttr();
        player.getAttrBox().setAttr(AttrConst.levelInst, Attr.of(attr));
    }
}
